*******************************************************************************
* Load data
*******************************************************************************

use dataset_voters, clear
keep if sample == "forthright"

*******************************************************************************
* > Loop over subsamples
*******************************************************************************

foreach G in 1 2 {

preserve
	
if `G' == 1 {
	keep if ideology_self < 0
	unique responseid
	local mytitle "Liberals (N=`r(sum)')"
}
if `G' == 2 {
	keep if ideology_self >= 0
	unique responseid
	local mytitle "Moderates/Conservatives (N=`r(sum)')"
}

*******************************************************************************
* Covariates
*******************************************************************************

local convictionrate convictionrate_3 convictionrate_4 ///
	convictionrate_5 convictionrate_6 convictionrate_7 convictionrate_8
local ageq ageq_2 ageq_3 ageq_4 ageq_5
local race race_2 race_3 race_4
local education education_2 education_3

#delimit;

local X 
	`convictionrate'
	`ageq'
	sex_2
	`race'
	`education'
	;

#delimit cr

*******************************************************************************
* Make interactions
*******************************************************************************

tabulate ideology, gen(ideology_cand_)
tabulate ideology_self, gen(ideology_self_)
tabulate distance, gen(distance_)
forvalues i = 1(1)7 {
	//gen adaXideology_self_`i' = ada*ideology_self_`i'
	label variable ideology_cand_`i' "Ideology=`i'"
	//label variable ideology_self_`i' "Ideology=`i'"
	label variable distance_`i' "Distance=`i'"
	//label variable adaXideology_self_`i' "Experienced X Ideology=`i'"
}
drop ideology_cand_1 /*adaXideology_self_1*/ distance_1 ideology_self_1

*******************************************************************************
* First regression
*******************************************************************************

//keep if ideology_self > 0
gen index = _n
gen B = .
gen Bcf = .
gen SE = .
gen SEcf = .

xi: reg vote ada distance_* `X', cl(responseid)

replace B = _b[ada] if index == 1
replace SE = _se[ada] if index == 1

su B
local myb = r(mean)

forvalues i = 2(1)7 {
	replace B = _b[distance_`i'] if index == `i'
	replace SE = _se[distance_`i'] if index == `i'
	replace Bcf = B + `myb' if index == `i'
	lincom distance_`i' + ada
	replace SEcf = r(se) if index == `i'
}

drop if mi(B)

collapse B SE Bcf SEcf, by(index)

replace index = index - 1

gen p = round(2*(1-normal(abs(B/SE))), 0.001)

replace Bcf = B if index == 0
replace SEcf = SE if index == 0
replace B = 0 if index == 0

gen UB = B + 1.96*SE if index > 0
gen LB = B - 1.96*SE if index > 0
gen UBcf = Bcf + 1.96*SEcf
gen LBcf = Bcf - 1.96*SEcf
gen pcf = round(2*(1-normal(abs(Bcf/SEcf))), 0.001)

#delimit;

gr tw
	(rspike UB LB index, lwid(thick) col(black))
	(sc B index, msym(O) col(black) mlab(p) mlabpos(12))
	(rspike UBcf LBcf index, col(gray))
	(sc Bcf index, col(white) msym(O) mlcol(gray) mlab(pcf) mlabpos(12))
	,
		yline(0, lpat(dash))
		xlab(0(1)6)
		legend(off)
		plotregion(style(none))
		ylab(, angle(horiz))
		xtitle("Ideological Distance")
		ytitle("Effect on Vote Choice")
		text(0.15 1.9 "+Experience Effect", col(gray))
		title("`mytitle'")
		;

#delimit cr

*******************************************************************************
* Output
*******************************************************************************

gr export "_output/figureS7_`G'.pdf", replace

*******************************************************************************
* > Close loop over subsamples
*******************************************************************************

restore

}

*******************************************************************************
* End
*******************************************************************************


